import static java.lang.Thread.sleep;

public class Test {
    public static void main(String[] args) {
        MyBlockingQueue<Integer> queue = new MyBlockingQueue<>();
        Thread t1 = new Thread(() -> {
            for(int i = 0; true; i++) {
                try {
                    queue.put(i);
                    System.out.println("添加元素: " + i);
                    sleep(3000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });

        Thread t2 = new Thread(() -> {
           while(true) {
               try {
                   System.out.println("取出元素: " + queue.take());
                   sleep(1000);
               } catch (InterruptedException e) {
                   throw new RuntimeException(e);
               }
           }
        });
        t1.start();
        t2.start();
    }
}
